package com.guldan.jaina.provider;

import com.guldan.core.dubbo.client.ResponseDTO;
import com.guldan.core.search.Pagination;
import com.guldan.jaina.common.filter.DubboContextRecorder;
import com.guldan.jaina.dto.area.AreaDTO;
import com.guldan.jaina.dto.area.AreaSearchDTO;
import com.guldan.jaina.dto.organization.OrganizationDTO;
import com.guldan.jaina.manager.AreaManager;

import java.util.List;

import com.guldan.jaina.utils.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created by Silas.
 * Date: 2016/11/7
 * Time: 22:54
 */
@Component
public class AreaProviderImpl implements IAreaProvider {

    @Autowired
    private AreaManager areaManager;

    @Override
    public ResponseDTO<AreaDTO> get(Integer areaId) {
        ResponseDTO<AreaDTO> response = new ResponseDTO<>();
        response.setData(areaManager.get(areaId));
        return response;
    }

    @Override
    public ResponseDTO<AreaDTO> save(AreaDTO dto) {
        ResponseDTO<AreaDTO> response = new ResponseDTO<>();
        try {
            response.setData(areaManager.save(dto));
        } catch (Exception ex) {
            response.setStatus(false);
            response.setException(ex);
        }
        return response;
    }

    @Override
    public ResponseDTO<Boolean> delete(Integer areaId) {
        ResponseDTO<Boolean> response = new ResponseDTO<>();
        response.setData(areaManager.delete(areaId));
        return response;
    }

    @Override
    public ResponseDTO<Pagination<AreaDTO>> list(AreaSearchDTO areaSearchDTO) {

        ResponseDTO<Pagination<AreaDTO>> response = new ResponseDTO<>();
        response.setData(areaManager.list(areaSearchDTO));
        return response;
    }
    
	@Override
	public ResponseDTO<Boolean> batchImport(List<AreaDTO> list) {
        ResponseDTO<Boolean> response = new ResponseDTO<>();
        response.setData(areaManager.batchImport(list));
        return response;
	}
}
